package company.permissionsystem.dao;

import company.permissionsystem.model.entity.SysUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDao {


    @Select("select * from sys_user where username=#{username}")
    SysUser findUserByUserName(String username);

    @Select("select * from sys_user where id=#{id}")
    SysUser findUserByUserId(Long id);

    @Select("select count(*) from sys_user")
    Long findCountByUser();

    @Select("select * from sys_user")
    @Results(id = "Map", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "department_id", property = "departmentId"),
            @Result(column = "position_id", property = "positionId"),

            @Result(property = "department", column = "department_id",
                    one = @One(select = "company.permissionsystem.dao.DepartmentDao.findDepartmentById", fetchType = FetchType.LAZY)),
            @Result(property = "position", column = "position_id",
                    one = @One(select = "company.permissionsystem.dao.PositionDao.findPositionById", fetchType = FetchType.LAZY)),
    })
    List<SysUser> findAllUser();

    @Update("update sys_user set status=#{status} where id=#{id};")
    void changeUserStatusById(SysUser sysUser);

    @Update("alter table sys_user drop id")
    public void file1();
    @Update("alter table sys_user add id int(3) first")
    public void file2();
    @Update("alter table sys_user modify column id int(3) not null auto_increment,add primary key(id)")
    public void file3();

}
